package com.archermind.style.controller;

import com.archermind.style.bean.DictColor;
import com.archermind.style.bean.DictDashLine;
import com.archermind.style.bean.DictFont;
import com.archermind.style.bean.DictFontSize;
import com.archermind.style.service.DictService;
import com.archermind.style.util.Result;
import com.archermind.style.util.Search;
import com.feng.fengDUtil.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/dict")
public class DictAction {

    @Autowired
    private DictService dictService;

    @RequestMapping(value = "/list")
    public Result list( Page page,Search search) {
        dictService.query(page,search);
        return Result.success(page);
    }

    @RequestMapping(value = "/dictReference")
    public Result queryDictReference( Page page,Search search) {
        dictService.dictReference(page,search);
        return Result.success(page);
    }

    @RequestMapping(value="/saveColor")
    public Result saveColor(@RequestBody DictColor dictColor){
        try {
            dictService.saveOrUpdate(dictColor);
            return Result.success(dictColor);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping(value="/saveFont")
    public Result saveFont(@RequestBody DictFont dictFont){
        try {
            dictService.saveOrUpdate(dictFont);
            return Result.success(dictFont);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping(value="/saveFontSize")
    public Result saveFont(@RequestBody DictFontSize dictFontSize){
        try {
            dictService.saveOrUpdate(dictFontSize);
            return Result.success(dictFontSize);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping(value="/saveDashLine")
    public Result saveDashLine(@RequestBody DictDashLine dashLine){
        try {
            dictService.saveOrUpdate(dashLine);
            return Result.success(dashLine);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping(value="/del")
    public Result del(String ids,String table){
        try {
            dictService.delDict(ids,table);
            return Result.success();
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }


   /* @RequestMapping(value="/copyColor")
    public Result copy(@RequestBody DictColor dict){
        try {
            dict.setId(null);
            dictService.insertAutoIncre(dict);
            return Result.success(dict);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping(value="/copyFont")
    public Result copy(@RequestBody DictFont dict){
        try {
            dict.setId(null);
            dictService.insertAutoIncre(dict);
            return Result.success(dict);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }


    @RequestMapping(value="/copyDashLine")
    public Result copy(@RequestBody DictDashLine dict){
        try {
            dict.setId(null);
            dictService.insertAutoIncre(dict);
            return Result.success(dict);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }*/




}